package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import bean.NotificationBean;

public class NotificationDao {
	public List<NotificationBean> getNotifications(int dormitoryId) throws ClassNotFoundException, SQLException {
		Connection conn = DBUtil.getConnection();
		PreparedStatement ps = conn.prepareStatement("select * from notification where dormitoryid=? order by notificationid desc");
		ps.setInt(1, dormitoryId);
		ResultSet rs = ps.executeQuery();
		List<NotificationBean> list = new ArrayList<NotificationBean>();
		while(rs.next()) {
			NotificationBean notification = new NotificationBean();
			notification.setId(rs.getInt(1));
			notification.setUserName(rs.getString(2));
			notification.setContent(rs.getString(3));
			notification.setDormitoryId(rs.getInt(4));
			notification.setTitle(rs.getString(5));
			list.add(notification);
		}
		return list;
	}
}
